package org.zhao.nettydemos.lab05;

import java.util.concurrent.*;

/**
 * @Auther: xiaohui.zhao
 * @Date: 2021/9/17 15:21
 * @Description: 测试future获取异步结果
 *
 * 使用Future接口或者其实现类FutureTask来接收任务的返回结果。
 * 使用Future接口往往配合线程池来获取异步执行结果
 */
public class FutureTest {

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        ExecutorService executorService = Executors.newSingleThreadExecutor();
        Future<String> future = executorService.submit(new Callable<String>() {
            @Override
            public String call() throws Exception {
                return "测试future获取异步结果";
            }
        });

        System.out.println(future.get());

        executorService.shutdown();
    }

}